package ua.dp.mzav.train.tm.model;

import java.io.Serializable;
import org.joda.time.DateTime;

/** Actually represents history item of LeaveRequest processing.
 */
public class LeaveRequestAction implements Serializable
{

   private static final long serialVersionUID = 1L;

   /// @serial Not null.
   private final DateTime when;

   /// @serial Not null.
   private final EmployeeReadable who;

   /// @serial Not null.
   private final LeaveRequestActions action;

   /// @serial Null means "not defined".
   private String comment;
   
   /** Constructor.
    * 
    * @param[in] aWhen Specifies date/time when the action is done.
    *                  Should not be null and should not be future
    * @param[in] aWho Specified Employee who performs the action.
    *                 Should not be null and should spevify registered Employee.
    * @param[in] anAction Should be not null.
    */
   LeaveRequestAction(final DateTime aWhen, 
                      final EmployeeReadable aWho,
                      final LeaveRequestActions anAction
                     )
   {
      if (aWhen == null  ||  aWhen.isAfter(new DateTime()))
      { 
         throw new java.lang.IllegalArgumentException("Argument aWhen in LeaveRequestAction is illegal");
      }
      if (aWho == null)
      { 
         throw new java.lang.IllegalArgumentException("Argument aWho in LeaveRequestAction is illegal");
      }
      if (anAction == null)
      { 
         throw new java.lang.IllegalArgumentException("Argument anAction in LeaveRequestAction is illegal");
      }
      
      when = aWhen;
      who = aWho;
      action = anAction;
   }
   
   /**  Date/time when the Action was occurred.
    * 
    * @return Not null. 
    */
   public final DateTime getWhen()
   {
      return when;
   }
   
   /** Employee who has caused the Action.
    * 
    * @return Not null. 
    */
   public final EmployeeReadable getWho()
   {
      return who;
   }
   
   /** Action type.
    * 
    * @return Not null.
    * @see LeaveRequestActions
    */
   public final LeaveRequestActions getAction()
   {
      return action;
   }
   
   /** Comment for the Action.
    * 
    * @retval null Means "comment was not specified".
    * @see LeaveRequestAction#setComment(java.lang.String) 
    */
   public final String getComment()
   {
      return comment;
   }

   /** Defines/modifies comment for the Action.
    * @param[in] aComment New value of comment.
    *                     null means "not specified".
    * @see LeaveRequestAction#getComment() 
    */
   public final void setComment(final String aComment)
   {
      comment = aComment != null  &&  aComment.isEmpty() ? null : aComment;
   }
}
